<?php abstract class DB implements iReconfigurable, iSignalHandler {
	protected static $Driver = '';
	public static function __Signals ($Sig = NULL) {
		if (NULL === $Sig) return (array (SIGUSR1, SIGUSR2));
		switch ($Sig) {
			case SIGUSR1:
				Out::I (Msg::SigHandled, $Sig);
				Daemon::Push2Q (array (__CLASS__, 'Unsee'));
			break;
			case SIGUSR2:
				Out::I (Msg::SigHandled, $Sig);
				Daemon::Push2Q (array (__CLASS__, 'DropSeen'));
			break;
		}
	}
	public static function Reconfigure (array $C) {
		// check config
		$Clean = TRUE;
		foreach (array ('driver', 'host', 'port', 'database', 'user', 'password', 'table', 'fetch_limit') as $Param) if (! array_key_exists ($Param, $C)) {
			Out::W (Msg::ConfigMiss, $Param);
			$Clean = FALSE;
		}
		// check for driver
		if (class_exists ($Drv = $C ['driver'])) {
			if (HasInterface ($Drv, 'iDBDriver')) {
				// check for missing extenstions
				$ExtMissing = array ();
				is_array ($Exts = call_user_func (array ($Drv, '__GetRequiredExtensions'))) or $Exts = array ($Exts);
				foreach ($Exts as $Ext) extension_loaded ($Ext) or array_push ($ExtMissing, $Ext);
				if (count ($ExtMissing)) {
					Out::W (Msg::ExtensionsMissing, implode (', ', $ExtMissing));
					$Clean = FALSE;
				} else self::$Driver = $Drv;
			} else {
				Out::W (Msg::DoesNotImplement, $Drv, 'iDBDriver');
				$Clean = FALSE;
			}
		} else {
			Out::W (Msg::ClassMissing, $Drv);
			$Clean = FALSE;
		}
		// connect already
		$Clean or Out::F (Msg::ConfigNotClean);
		call_user_func (array ($Drv, 'Open'), $C ['host'], $C ['port'], $C ['database'], $C ['user'], $C ['password'], $C ['table'], $C ['fetch_limit']) or Out::F (Msg::DBConnectionFail, $Drv);
	}
	public static function Drop (array $Ids) {return (call_user_func (array (self::$Driver, __FUNCTION__), $Ids));}
	public static function See (array $Ids)  {return (call_user_func (array (self::$Driver, __FUNCTION__), $Ids));}
	public static function Know (array $Ids) {return (call_user_func (array (self::$Driver, __FUNCTION__), $Ids));}
	public static function Fetch ()          {return (call_user_func (array (self::$Driver, __FUNCTION__)));}
	public static function Unsee ()          {return (call_user_func (array (self::$Driver, __FUNCTION__)));}
	public static function DropSeen ()       {return (call_user_func (array (self::$Driver, __FUNCTION__)));}
} ?>